package com.road.vast.company.service.impl;

import com.road.vast.company.mapper.CoCompanyMapper;
import com.road.vast.company.service.CoCompanyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.road.vast.component.IdWorkerComponent;
import com.road.vast.pojo.company.CoCompany;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 郭泽鹏
 * @since 2020-06-30
 */
@Service
public class CoCompanyServiceImpl extends ServiceImpl<CoCompanyMapper, CoCompany> implements CoCompanyService {
    @Resource
    private CoCompanyMapper coCompanyMapper;

    @Autowired
    private IdWorkerComponent idWorkerComponent;

    @Override
    public Integer add(CoCompany coCompany) {
//        CoCompany coCompany = new CoCompany();
        //雪花算法获取id
        String nextId = idWorkerComponent.getIdWorker().nextId() + "";
        coCompany.setId(nextId);
//        coCompany.setName("RoadVast");
//        coCompany.setManagerId("2247820352");
//        coCompany.setVersion("1");
//
//        SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
//        String str1="1998/04/07 10:11:12";
//        String str2="2038/01/25 23:11:12";
//        try {
//            Date date = sdf.parse(str1);
//            coCompany.setRenewalDate(sdf.parse(str1));
//            coCompany.setExpirationDate(sdf.parse(str2));
//        } catch (ParseException e) {
//            e.printStackTrace();
//        }
//        coCompany.setCompanyArea("广东省");
//        coCompany.setCompanyAddress("广东省汕头市");
//        coCompany.setManagerId("image.id");
//        coCompany.setLegalRepresentative("Guo ZePeng");
//        coCompany.setCompanyPhone("0754-87587596");
//        coCompany.setMailbox("2247820352@qq.com");
//        coCompany.setCompanySize("Middle");
//        coCompany.setIndustry("计算机");
//        coCompany.setRemarks("备注内容");
//        coCompany.setAuditState("0");
//        coCompany.setState(0);
//        coCompany.setBalance(2500.0);
        int insert = coCompanyMapper.insert(coCompany);
        return insert;
    }

    @Override
    public Integer updateCoCompany(CoCompany coCompany) {
        CoCompany coCompany1 = coCompanyMapper.selectById(coCompany.getId());
        coCompany1.setName(coCompany.getName());
        coCompany1.setCompanyPhone(coCompany.getCompanyPhone());
        int update = coCompanyMapper.updateById(coCompany1);
        return update;
    }

    @Override
    public Integer delete(String id) {
        return coCompanyMapper.deleteById(id);
    }

    @Override
    public CoCompany findById(String id) {
        return coCompanyMapper.selectById(id);
    }

    @Override
    public List<CoCompany> findAll() {
        return coCompanyMapper.selectList(null);
    }

    @Override
    public Integer updateAuditState(String id) {
        CoCompany coCompany = new CoCompany();
        coCompany.setId(id);
        coCompany.setAuditState("1");
        return coCompanyMapper.updateById(coCompany);
    }

    @Override
    public Integer updateRefuse(String id) {
        CoCompany coCompany = new CoCompany();
        coCompany.setId(id);
        coCompany.setAuditState("0");
        return coCompanyMapper.updateById(coCompany);
    }
}
